﻿@using KMF.WebUI.Areas.KMFadmin.Models
@using KMF.WebUI.Areas.KMFadmin.CustomHelpers
@model IEnumerable<KMF.Common.ProductAllPagingDto>
@{
    ViewBag.Title = "ProductByCate";
    Layout = "~/Areas/KMFadmin/Views/Shared/_layout.cshtml";
}
@section LeftMenu
{
    <div id="left">
        <div class="LeftMenuWraper">
            <div class="leftMenuHeader">
                <span style="padding-left: 10px;">
                    <strong>Truy cập nhanh</strong>
                </span>
            </div>
            <ul id="p-quick-menu" class="quick-menu">
                <li class="qmn-info-pro">
                    <a href="@Url.Action("Index", "AdminProductCategory")">Thông tin danh mục</a>
                </li>
                <li class="qmn-info-pro">
                    <a href="@Url.Action("Index", "AdminProduct")">Danh sách sản phẩm</a>
                </li>
            </ul>
            <div class="leftMenuFooter"></div>
        </div>
    </div>
    <!-- END #left -->
}
<nav>
    <div class="breadCrumb">
        <ul>
            <li><a href="@Url.Action("Index", "AdminHome")"><i class="bootstrap icon-home"></i></a></li>
            <li><a href="javascript:void(0)">Sản phẩm</a> </li>
            <li><a href="@Url.Action("Index", "AdminProduct")">Danh sách sản phẩm</a> </li>
        </ul>
    </div>
</nav>
<div class="toolBox">
    @Html.ToolBox(new List<object> { new Add { ClassCss = "Add", ActionName = "/KMFadmin//AdminProduct/Add" } })
</div>
<div>
    @Html.DropDownList("CategoryList", new SelectList(ViewBag.MenuList, "Id", "Name"), new { })
    @using (Html.BeginForm("SearchProduct", "AdminProduct"))
    {
        @Html.TextBox("keyword", "", new { @style = "width:280px;" })
        <input type="submit" value="Tìm kiếm" />
    }
    @Html.Hidden("CategoryId", (string)ViewBag.CateId)
</div>
<table class="table-odd table-plist">
    <tr>
        <th style="width: 10px;">STT</th>
        <th style="width: 3%;">Ảnh</th>
        <th style="width: 6%;">Mã sp</th>
        <th>Tên</th>
        <th style="width: 10%;">Giá</th>
        <th style="width: 11%;"></th>
    </tr>
    @foreach(var item in Model)
    {
        <tr>
            <td>@item.STT</td>
            <td>
                <img src="@item.ImagePath.ImagePathThumb(50,50)"/>
            </td>
            <td>
                @item.Barcode
            </td>
            <td>
               <a href="@Url.Action("Edit", "AdminProduct", new { id = @item.Id })">@item.Name</a>
                <div class="info-ad-qv">
                    <a href="">Sửa nhanh</a> |
                    <a href="javascript:void(0);" onclick="DeleteProduct(this,@item.Id)" class="ad-qv-txt2">Xóa</a> |
                    @{
        var htmlMeta = FunctionHelper.returnConfig("Domainname");
        var ViewDetail = htmlMeta + '/' + KMF.Utility.StringUtil.RemoveSpecialCharactersVn(item.Name) + "-" + item.Id + ".html";
                    }
                    <a href="@ViewDetail" target="_blank">Xem</a>
                </div>

            </td>
            <td>
                <input type="text" value="@string.Format("{0:#,###}",item.Price)"/>
            </td>
            <td>
                <a href="">Update</a>
            </td>
        </tr>
    }
</table>
<div class="p-paging">
    @Html.PageLinks((PageInfo)ViewBag.PageInfo, i => Url.Action("ProductByCate", "AdminProduct", new { page = i, categoryId = ViewBag.CateId }))
</div>
@section scripts
{
    <script type="text/javascript">
        function DeleteProduct(_cmd, id) {
            var cmd = $(_cmd);
            if (confirm('Bạn chắc chắn muốn xóa sản phẩm này!')) {
                $.ajax({
                    url: '/KMFadmin/AdminProduct/DeleteProduct',
                    data: { id: id },
                    success: function (data) {
                        if (data) {
                            alert('Xóa sản phẩm thành công!');
                            //window.location = '/Product';
                            cmd.parent().parent().parent().fadeOut();
                        }
                        else {
                            alert('Đã có lỗi xảy ra!');
                        }
                    },
                    error: function () {
                        alert('Đã có lỗi xảy ra!');
                    }
                });
            }
        }

        var currentCate = $('#CategoryId').val();
        $('#CategoryList option[value=' + currentCate + ']').attr('selected', 'selected');

        $('#CategoryList').change(function () {
            var cateId = $(this).val();
            window.location = '/KMFadmin/AdminProduct/ProductByCate?page=1&categoryId=' + cateId;
        });
    </script>
}
